<?php
/**
 * Groups module for XOOPS
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code 
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright       The Groups Project http://code.google.com/p/groupsforxoops/
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
 * @package         groups
 * @since           2.3.0
 * @author          Hui Xiao < xh.8326@gmail.com >
 * @version         $Id: ajax.admin.php Sat Jul 18 12:45:27 CST 2009
 */

include "conf.inc";
header("Content-Type:text/html; charset="._CHARSET);

$group_id = isset($_GET["gid"]) ? intval($_GET["gid"]) : 0;
$op = isset($_GET["op"]) ? trim($_GET["op"]) : "";

$column_handler = xoops_getmodulehandler("column","groups");
$groups_handler = xoops_getmodulehandler("groups","groups");
$threads_handler = xoops_getmodulehandler("threads","groups");
$posts_handler = xoops_getmodulehandler("posts","groups");

/** 检查来访者权限 **/
if ( empty($xoopsUser) || !is_object($xoopsUser) ) {
    $op = "noperm";
} 

$group_obj = $groups_handler->get($group_id);
if ( $op != "delevent" && $op != "delpost" ) {
    if ( $op == "noperm" || !is_object($group_obj) || $group_obj->isNew() || $group_obj->getVar("uid") != $xoopsUser->getVar("uid") ) {
        $op = "noperm";
    }
} else {
    if ( false == getIsGroupsAdmin($group_id,$xoopsUser->getVar("uid")) ) {
		$op = "noperm";
	}
}

switch ($op) {
    /** 删除主题 **/
    case "delpost":
        $post_id = isset($_GET["pid"]) ? intval($_GET["pid"]) : 0;
        $formUrl = XOOPS_URL_DEFAULT."/modules/{$xoopsModule->getVar("dirname","n")}/user/action.user.php";
        echo xoops_groups_ajax_confirm(array("post_id"=>$post_id,"group_id"=>$group_id,"ac"=>"delpost"),$formUrl,_GP_CONFIRM_DELPOST);
        exit();
    break;
    /** 删除事件 **/
    case "delevent":
        $event_id = isset($_GET["eid"]) ? intval($_GET["eid"]) : 0;
        $formUrl = XOOPS_URL_DEFAULT."/modules/{$xoopsModule->getVar("dirname","n")}/user/action.user.php";
        echo xoops_groups_ajax_confirm(array("event_id"=>$event_id,"group_id"=>$group_id,"ac"=>"delevent"),$formUrl,_GP_CONFIRM_DELEVENT);
        exit();
    break;
    /** 删除公告 **/
    case "delnotice":
        $notice_id = isset($_GET["nid"]) ? intval($_GET["nid"]) : 0;
        $formUrl = XOOPS_URL_DEFAULT."/modules/{$xoopsModule->getVar("dirname","n")}/user/action.user.php";
        echo xoops_groups_ajax_confirm(array("notice_id"=>$notice_id,"group_id"=>$group_id,"ac"=>"delnotice"),$formUrl,_GP_CONFIRM_DELNOTICE);
        exit();
    break;
    
    /** 删除群组成员 */
    case "remove":
        $member_id = isset($_GET["id"]) ? intval($_GET["id"]) : 0;
        $formUrl = XOOPS_URL_DEFAULT."/modules/{$xoopsModule->getVar("dirname","n")}/user/action.user.php";
        echo xoops_groups_ajax_confirm(array("member_id"=>$member_id,"group_id"=>$group_id,"ac"=>"removemember"),$formUrl,_GP_CONFIRM_DELMEMBER);
        exit();
    break;
    
    case "cenceladmin":
    case "addadmin":
        $member_id = isset($_GET["id"]) ? intval($_GET["id"]) : 0;
        $isadmin = ($op == "addadmin") ? 1 : 0;
        $msg = !empty($isadmin) ? _GP_CONFIRM_JOINADMIN : _GP_CONFIRM_CANCELADMIN;
        $formUrl = XOOPS_URL_DEFAULT."/modules/{$xoopsModule->getVar("dirname","n")}/user/action.user.php";
        echo xoops_groups_ajax_confirm(array("member_id"=>$member_id,"group_id"=>$group_id,"isadmin"=>$isadmin,"ac"=>"opadmin"),$formUrl,$msg);
        exit();
    break;
    
    case "passmember":
        $member_id = isset($_GET["id"]) ? intval($_GET["id"]) : 0;
        $msg = _GP_CONFIRM_PASSMEMBER;
        $formUrl = XOOPS_URL_DEFAULT."/modules/{$xoopsModule->getVar("dirname","n")}/user/action.user.php";
        echo xoops_groups_ajax_confirm(array("member_id"=>$member_id,"group_id"=>$group_id,"ac"=>"passmember"),$formUrl,$msg);
        exit();
    break;
    
    case "noperm":
    default:
        echo _NOPERM;
        exit();
    break;
}

?>